import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';


@Injectable({
    providedIn: 'root'
})
export class TutorialService {

    private resourceUrl = 'api/tutorial';

    constructor(private http: HttpClient) {}

    postMarkdownFile(json): Observable<any> {
        return this.http.post<any>(this.resourceUrl + '/upload/markdownfile', json);
    }

    getMarkdownFile(id): Observable<any> {
        return this.http.get<any>(this.resourceUrl + '/markdownfile/' + id);
    }

    getMarkdownFileInfos(catalog): Observable<any> {
        return this.http.get<any>(this.resourceUrl + '/markdownfileInfos/' + catalog);
    }
    generateNewMarkdownFile(fileName: string, author: string, date: string): Observable<any> {
        return this.http.post<any>(this.resourceUrl + '/markdown/new',
          {filename: fileName, author: author, date: date});
    }
    deleteMarkdownFiles(fileIds: number[]): Observable<any> {
        return this.http.post<any>(this.resourceUrl + '/markdown/delete', {fileIds:fileIds} );
    }
    updateMarkdownFile(json: any): Observable<any> {
        return this.http.post<any>(this.resourceUrl + '/markdown/update', json);
    }

}
